home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / STDLIB.PAK / SET_INTR.CPP < prev    next >
Text File  |  1997-05-06  |  902b  |  33 lines

  1.  #include <algorithm>
  2.  #include <set>
  3.  
  4.  using namespace std;
  5.  
  6.  int main ()
  7.  {
  8.    //
  9.    // Initialize some sets.
  10.    //
  11.    int a1[10] = {1,3,5,7,9,11};
  12.    int a3[4]  = {3,5,7,8};
  13.    set<int, less<int> > odd(a1+0, a1+6), result, smalll(a3+0, a3+4);
  14.    //
  15.    // Create an insert_iterator for result.
  16.    //
  17.    insert_iterator<set<int, less<int> > > res_ins(result, result.begin());
  18.    //
  19.    // Demonstrate set_intersection.
  20.    //
  21.    cout << "The result of:" << endl << "{";
  22.    copy(smalll.begin(),smalll.end(), ostream_iterator<int>(cout," "));
  23.    cout << "} intersection {";
  24.    copy(odd.begin(),odd.end(), ostream_iterator<int>(cout," "));
  25.    cout << "} =" << endl << "{";
  26.    set_intersection(smalll.begin(),smalll.end(),odd.begin(),odd.end(),res_ins);
  27.    copy(result.begin(),result.end(), ostream_iterator<int>(cout," "));
  28.    cout << "}" << endl << endl;
  29.  
  30.    return 0;
  31.  }
  32.  
  33.